package com.ps.util;

import java.util.UUID;
import java.util.function.Predicate;

public class Util {
    public static String UUID() {
        return UUID.randomUUID().toString();
    }


    public static <T> T find(Iterable<T> list, Predicate<T> predicate) {
        if (list == null) return null;
        for (T t : list) {
            if (predicate.test(t)) return t;
        }
        return null;
    }

    public static <T> int findIndex(Iterable<T> list, Predicate<T> predicate) {
        int i = -1;
        if (list == null) return i;
        for (T t : list) {
            i++;
            if (predicate.test(t)) return i;
        }
        return -1;
    }

}
